# -*- coding: utf-8 -*-
"""
Web framework/Tornado Router/test01.py
"""
import tornado.web
import asyncio
from tornado.httpserver import HTTPServer
from tornado.routing import Router


class UserHandler(tornado.web.RequestHandler):
    def get(self):
        r_message = "Welcome to UserHandler Get Method."
        self.finish(r_message)


class PhotoHandler(tornado.web.RequestHandler):
    def get(self):
        r_message = "Welcome to PhotoHandler Get Method."
        self.finish(r_message)


class HTTPPathRouter(Router):
    def __init__(self, app):
        self.app = app

    def find_handler(self, request, **kwargs):
        _path = request.path
        if '/user/' in _path:
            handler = UserHandler
        else:
            handler = PhotoHandler

        return self.app.get_handler_delegate(request=request, target_class=handler)


async def main():
    router = HTTPPathRouter(tornado.web.Application())
    sever = HTTPServer(router)
    sever.listen(8888)
    await asyncio.Event().wait()


if __name__ == '__main__':
    asyncio.run(main())
